using System.Data;
using System.Data.SqlClient;
using DataAccessLayer;
using EntityObjectLayer;

namespace BusinessLogicLayer
{
    public class BLTeacher
    {
        public int Saved(BETeacher beteacher, string Type)
        {
            SqlParameter ID = new SqlParameter("@ID", SqlDbType.Char, 10);
            ID.Value = beteacher.sID;
            SqlParameter FullName = new SqlParameter("@FullName", SqlDbType.NVarChar, 30);
            FullName.Value = beteacher.sFullName;
            SqlParameter Birth = new SqlParameter("@Birth", SqlDbType.DateTime, 8);
            Birth.Value = beteacher.daBirth;
            SqlParameter Gender = new SqlParameter("@Gender", SqlDbType.Bit, 1);
            Gender.Value = beteacher.bGender;
            SqlParameter Address = new SqlParameter("@Address", SqlDbType.NVarChar, 50);
            Address.Value = beteacher.sAddress;
            SqlParameter Email = new SqlParameter("@Email", SqlDbType.VarChar, 30);
            Email.Value = beteacher.sEmail;
            SqlParameter Phone = new SqlParameter("@Phone", SqlDbType.VarChar, 20);
            Phone.Value = beteacher.sPhone;
            SqlParameter MajorSubject = new SqlParameter("@MajorSubject", SqlDbType.NVarChar, 20);
            MajorSubject.Value = beteacher.sMajorSubject;
            SqlParameter Qualification = new SqlParameter("@Qualification", SqlDbType.NVarChar, 20);
            Qualification.Value = beteacher.sQualification;
            SqlParameter EnterDate = new SqlParameter("@EnterDate", SqlDbType.DateTime, 8);
            EnterDate.Value = beteacher.daEnterDate;
            SqlParameter ReleaseDate = new SqlParameter("@ReleaseDate", SqlDbType.DateTime, 8);
            ReleaseDate.Value = beteacher.daReleaseDate;
            SqlParameter Status = new SqlParameter("@Status", SqlDbType.NVarChar, 30);
            Status.Value = beteacher.sStatus;

            int returnInt = 0;
            switch (Type)
            {
                case "Insert":
                    returnInt = Common.Execute("pr_tblTeacher_Insert", ID, FullName, Birth, Gender, Address, Email,
                                               Phone, MajorSubject, Qualification, EnterDate, ReleaseDate, Status);
                    break;
                case "Update":
                    returnInt = Common.Execute("pr_tblTeacher_Update", ID, FullName, Birth, Gender, Address, Email,
                                               Phone, MajorSubject, Qualification, EnterDate, ReleaseDate, Status);
                    break;
            }
            return returnInt;
        }

        public int Delete(BETeacher beteacher)
        {
            SqlParameter ID = new SqlParameter("@ID", SqlDbType.Char, 10);
            ID.Value = beteacher.sID;
            return Common.Execute("pr_tblTeacher_Delete", ID);
        }

        public DataSet SelectAll()
        {
            DataTable dt = Common.GetFromDataTable("pr_tblTeacher_SelectAll");
            return dt.DataSet;
        }

        public string getID()
        {
            return Common.getID("TC", "pr_tblTeacher_GetID");
        }
    }
}